import {View, Block} from '@tarojs/components';
import React from 'react';
import './good-info-box.scss';

interface Info {
  info: any
  type?: any
  goodstext?: string
}

const GoodInfoBox: React.FC<Info> = ({info, type, goodstext='可用时间'}) => {
  const isHYG = (process.env.P_ENV === 'hiyogo' || process.env.P_ENV === 'vc') // 抢购时间和自动取消，嗨游购环境不显示
  return (
    <Block>
      {info &&
      <View className={`good-info-box ${type === 'limited' && 'good-info-box-no-padding'}`}>
        {!isHYG && <View className='good-info-item'>
          <View className='title'>抢购时间：</View>
          <View className='text'>{info.sell_begin_show}{info.sell_end_show ? ` 至 ${info.sell_end_show}` : ''}</View>
        </View>}
        {!isHYG && process.env.P_ENV !== 'kd' && <View className='good-info-item'>
          <View className='title'>自动取消：</View>
          <View className='text'>下单后{info.good_cancel_order_time}分钟内不完成支付自动取消</View>
        </View>}
        {!!info.valid_date_type && (info.effective_begin_show || info.effective_end_show) &&
        <View className='good-info-item'>
          <View className='title'>{goodstext ? goodstext + ':' : '可用时间：'}</View>
          <View className='text'>{info.effective_begin_show}{info.effective_end_show ? ` ${info.effective_end_show}` : ''}</View>
        </View>}
        {!info.valid_date_type &&
        <View className='good-info-item'>
          <View className='title'>{goodstext ? goodstext + ':' : '可用时间：'}</View>
          <View className='text'>长期有效</View>
        </View>}
        {process.env.P_ENV !== 'kd' && info.valid_date_time_begin &&
        <View className='good-info-item'>
          <View className='title'>验票时间：</View>
          <View className='text'>{info.valid_date_time_begin}{info.valid_date_time_end ? ` 至 ${info.valid_date_time_end}` : ''}</View>
        </View>}
        {!info.is_time_show && info.bookingEndShow &&
        <View className='good-info-item'>
          <View className='title'>生效时间：</View>
          <View className='text'>{info.bookingEndShow}</View>
        </View>}
        {info.isGetTicketWay && info.ticketWayStr &&
        <View className='good-info-item'>
          <View className='title'>{isHYG ? '使用方式' : '取票方式'}</View>
          <View className='text'>{info.ticketWayStr || ''}</View>
        </View>}
      </View>}
    </Block>
  )
}

export default GoodInfoBox
